
// Definition for singly-linked list.
function ListNode(val, next) {
    this.val = (val===undefined ? 0 : val)
    this.next = (next===undefined ? null : next)
}
function createList(arr) {
  if(!arr.length) return null;
  let root = new ListNode(arr[0], null), temp = root;
  for(let i = 1; i < arr.length; i++) {
    let node = new ListNode(arr[i], null);
    temp.next = node;
    temp = temp.next;
  }
  return root;
}

function showList(head) {
  let temp = head, result = [];
  while(temp) {
    result.push(temp.val);
    temp = temp.next;
  }
  console.log(result.join('->'));
}

/**
 * @param {ListNode[]} lists
 * @return {ListNode}
 */
var mergeKLists = function(lists) {
  let listHead = [], listLength = [];
  for(let i = 0; i < lists.length; i++) {
    let head = createList(lists[i]);
    listHead.push(head);
    // showList(head);
  }
  let result = listHead[0];
  for(let i = 1; i < listHead.length; i++) {
    let temp = result, newHead = listHead[i];
    while(newHead && temp) {
      let node = null;
      if(newHead.val < temp.val) {
        node = newHead.next;
        newHead = newHead.next;
      } else {

      }
    }
  }
  return result;
};
let lists = [[1,4,5],[1,3,4],[2,6]];
console.log(mergeKLists(lists));
lists = [];
console.log(mergeKLists(lists));
lists = [[]];
console.log(mergeKLists(lists));
